package com.study.zzedu.fragment.coursetab;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.study.zzedu.R;
import com.study.zzedu.adapter.CourseDetailAdapter;
import com.study.zzedu.entity.CourseDetailItem;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.Utils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import static com.study.zzedu.ui.courseintroduce.CourseIntroduceActivity.teachingPlan;

/**
 */

public class TeachPlanFragment extends Fragment {

    private List<CourseDetailItem> dataList = new ArrayList<CourseDetailItem>();
    CourseDetailAdapter courseDetailAdapter;
    RecyclerView mRecyclerView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_teaching_plan, container, false);
        initView(rootView);
        return rootView;
    }
    protected void initView(View view) {

        mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_list_data);
        LinearLayoutManager lm = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(lm);

        try {
            if(teachingPlan == null)
                return;
            JSONObject job = teachingPlan;
            dataList.add(new CourseDetailItem("计划号", Utils.getDefaultStringValue(job,"jhh"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("入学年份",Utils.getDefaultStringValue(job,"rxnf"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("选修限制批次",Utils.getDefaultStringValue(job,"xxpc"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("课程类别A",Utils.getDefaultStringValue(job,"kclb_a"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("课程类别B",Utils.getDefaultStringValue(job,"kclb_b"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("学分",Utils.getDefaultStringValue(job,"xf"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("考试形式",Utils.getDefaultStringValue(job,"ksxs"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("考试级别",Utils.getDefaultStringValue(job,"ksjb"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("课程名",Utils.getDefaultStringValue(job,"kc"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("计分方式",Utils.getDefaultStringValue(job,"jffs"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("在线测试分数比例",Utils.getDefaultStringValue(job,"bl_zyms"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("期末考试分数比例",Utils.getDefaultStringValue(job,"bl_qmks"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("网上学习分数比例",Utils.getDefaultStringValue(job,"bl_wsxx"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("在线测试分数比例",Utils.getDefaultStringValue(job,"bl_zxcs"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("学时",Utils.getDefaultStringValue(job,"xs"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("专业",Utils.getDefaultStringValue(job,"zy"),CourseDetailItem.TYPE_STRING));

            view.findViewById(R.id.rl_default_teach_plan).setVisibility(View.GONE);
        }catch (Exception e){
            LogUtil.e("Exception",getActivity()+" "+e.toString());
            e.toString();
        }
        courseDetailAdapter = new CourseDetailAdapter(dataList);
        //mRecyclerView.addItemDecoration(new SpacesItemDecoration(30));
        mRecyclerView.setAdapter(courseDetailAdapter);
    }
}
